package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SuperComment;
import com.ruoyi.system.mapper.SuperCommentMapper;
import io.jsonwebtoken.Claims;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SuperMerchantReplyMapper;
import com.ruoyi.system.domain.SuperMerchantReply;
import com.ruoyi.system.service.ISuperMerchantReplyService;

import javax.annotation.Resource;

/**
 * 商家回复评论Service业务层处理
 * 
 * @author xjf
 * @date 2025-08-13
 */
@Service
public class SuperMerchantReplyServiceImpl implements ISuperMerchantReplyService 
{
    @Autowired
    private SuperMerchantReplyMapper superMerchantReplyMapper;
    @Autowired
    private SuperCommentMapper superCommentMapper;

    /**
     * 查询商家回复评论
     * 
     * @param id 商家回复评论主键
     * @return 商家回复评论
     */
    @Override
    public SuperMerchantReply selectSuperMerchantReplyById(Long id)
    {
        return superMerchantReplyMapper.selectSuperMerchantReplyById(id);
    }

    /**
     * 查询商家回复评论列表
     * 
     * @param superMerchantReply 商家回复评论
     * @return 商家回复评论
     */
    @Override
    public List<SuperMerchantReply> selectSuperMerchantReplyList(SuperMerchantReply superMerchantReply)
    {
        return superMerchantReplyMapper.selectSuperMerchantReplyList(superMerchantReply);
    }

    /**
     * 新增商家回复评论
     * 
     * @param superMerchantReply 商家回复评论
     * @return 结果
     */
    @Override
    public int insertSuperMerchantReply(SuperMerchantReply superMerchantReply)
    {
        superMerchantReply.setCreateTime(DateUtils.getNowDate());
        return superMerchantReplyMapper.insertSuperMerchantReply(superMerchantReply);
    }



    /**
     * 修改商家回复评论
     * 
     * @param superMerchantReply 商家回复评论
     * @return 结果
     */
    @Override
    public int updateSuperMerchantReply(SuperMerchantReply superMerchantReply)
    {

        superMerchantReplyMapper.updateSuperMerchantReply(superMerchantReply);
        SuperComment superComment = new SuperComment();
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        superComment.setUserId(user.getUserId());
        SuperComment comment = superMerchantReply.getComment();
        superComment.setProductId(comment.getProductId());
        superComment.setContent(superMerchantReply.getContent());
        return superCommentMapper.insertSuperComment(superComment);
    }

    /**
     * 批量删除商家回复评论
     * 
     * @param ids 需要删除的商家回复评论主键
     * @return 结果
     */
    @Override
    public int deleteSuperMerchantReplyByIds(Long[] ids)
    {
        return superMerchantReplyMapper.deleteSuperMerchantReplyByIds(ids);
    }

    /**
     * 删除商家回复评论信息
     * 
     * @param id 商家回复评论主键
     * @return 结果
     */
    @Override
    public int deleteSuperMerchantReplyById(Long id)
    {
        return superMerchantReplyMapper.deleteSuperMerchantReplyById(id);
    }
}
